package com.windfone.common;

import java.util.Properties;

import javax.mail.Session;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public class SingleMailSend {
	private String toAddress;
	private String content;
	private String title;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getToAddress() {
		return toAddress;
	}

	public void setToAddress(String toAddress) {
		this.toAddress = toAddress;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void send() {
		JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
		senderImpl.setHost("mail.windfone.com");
		SimpleMailMessage mailMessage = new SimpleMailMessage();

		mailMessage.setTo(toAddress);
		mailMessage.setFrom("windfone@windfone.com");
		mailMessage.setSubject( title);
		mailMessage.setText( content );

		senderImpl.setUsername("windfone");
		senderImpl.setPassword("Ba1978314");

		Properties prop = new Properties();
		prop.put("mail.smtp.auth", "true");
		prop.put("mail.smtp.timeout ", "25000");
		prop.put("mail.smtp.host", "mail.windfone.com");

		MyAuthenticator myauth = new MyAuthenticator("windfone@windfone.com","Ba1978314");
		Session session = Session.getDefaultInstance(prop, myauth);
		senderImpl.setSession(session);
		senderImpl.send(mailMessage);

	}
}
